//引入工具类
const util = require('../../utils/util');
// 加载配置文件
const config = require('../../utils/config');

const app = getApp()

Page({
    data: {
        title: '',
        content: '',
        imgUrl: ''
    },
    onLoad: function(options) {
        console.log(options, '');
        var _this = this;
        _this.setData({
            pageTitle: options.name
        })
        wx.setNavigationBarTitle({
            title: _this.data.pageTitle
        })

        wx.showLoading({
            title: '加载中...'
        })
        _this.setData({
            id: options.id
        })
        let apiUrl = 'msg/findById'
        if (this.data.pageTitle == "公告") {
            apiUrl = 'ad/findById'
        }
        app.ajax({
            url: `${config.httpUrl}${apiUrl}`,
            method: 'get',
            data: {
                id: _this.data.id
            },
            callback: function(error, data) {
                console.log(data, '');
                wx.hideLoading();
                _this.setData({
                    title: data.data.title,
                    content: data.data.content,
                    imgUrl: data.data.img_url || ''
                })
            }
        })
    },
    onShow() {
        let pages = getCurrentPages();
        let curPage = pages[pages.length - 1];
        app.checkBind(curPage.route);
    }
})